﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Art
{
    public sealed class ColorChannelTemplate
    {
        private readonly String name, shortName;
        
        public ColorChannelTemplate(String name)
        {
            this.name = name;
            if (!String.IsNullOrEmpty(name)) this.shortName = name.Substring(0, 1);
        }

        public ColorChannelTemplate(String name, String shortName)
        {
            this.name = name;
            this.shortName = shortName;
        }

        public static implicit operator ColorChannelTemplate(String value)
        {
            return new ColorChannelTemplate(value);
        }

        public String Name { get { return this.name; } }
        public String ShortName { get { return this.shortName; } }

        public override Boolean Equals(Object obj)
        {
            if (obj == null) return false;
            else if (obj.GetType() != typeof(ColorChannelTemplate)) return false;
            else
            {
                var other = (ColorChannelTemplate)obj;
                return this.name == other.name && this.shortName == other.shortName;
            }
        }

        public override Int32 GetHashCode()
        {
            return this.name.GetHashCode();
        }
    }

    public sealed class ColorChannel
    {
        private readonly ColorSpaceBase owner;
        private readonly ColorChannelTemplate template;

        internal ColorChannel(ColorSpaceBase owner, ColorChannelTemplate template)
        {
            this.owner = owner;
            this.template = template;
        }

        public String Name { get { return this.template.Name; } }
        public String ShortName { get { return this.template.ShortName; } }
        public ColorSpaceBase Owner { get { return this.owner; } }

        public override Boolean Equals(Object obj)
        {
            if (obj == null) return false;
            else if (obj.GetType() != typeof(ColorChannel)) return false;
            else
            {
                var other = (ColorChannel)obj;
                return this.owner == other.owner && this.template == other.template;
            }
        }

        public override Int32 GetHashCode()
        {
            return this.owner.GetHashCode() ^ this.template.GetHashCode();
        }
    }
}
